package org.apogee.mil.client.utils;

import java.util.Date;

import com.google.gwt.user.client.Cookies;

public class Session {
	
	private static final long DEFAULT_DURATION = 1000 * 60 * 60 * 24;
	
	private static int sid;
	
	public static void setSession(int sessionId) {
		setSession(sessionId, DEFAULT_DURATION);
	}
	
	public static void setSession(int sessionId, long duration) {
		Date expires = new Date(System.currentTimeMillis() + duration);
		Cookies.setCookie("sid", String.valueOf(sessionId), expires, null, "/", false);
		sid = sessionId;
	}
	
	public static int getSessionId() {
		
		if (Cookies.getCookie("sid") == null) {
			return sid;
		}
		
		return Integer.valueOf(Cookies.getCookie("sid"));
	}
	
	
}
